package net.xdclass.video.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.xdclass.video.Exception.ServiceException;
import net.xdclass.video.entity.Collect;
import net.xdclass.video.entity.Details;
import net.xdclass.video.entity.Records;
import net.xdclass.video.mapper.CollectMapper;
import net.xdclass.video.mapper.DetailsMapper;
import net.xdclass.video.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.rmi.ServerException;
import java.util.Date;
import java.util.List;

@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {
    @Autowired
    private CollectMapper collectMapper;
    @Autowired
    private DetailsMapper detailsMapper;
    @Override
    public void saveOne(String username, String name) {
        Collect selectUserName=collectMapper.selectUserName(username,name);
        if (selectUserName == null){

            String url=detailsMapper.selectCover(name);
            Collect collect = new Collect();
            collect.setName(name);
            collect.setUsername(username);
            collect.setStatus(1);
            collect.setCover(url);
            collectMapper.insert(collect);
        }else {
            throw new ServiceException("已收藏过了，亲");
        }
    }

    @Override
    public List<Collect> collectVideoAll(String username) {

        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        queryWrapper.orderByDesc("createtime");
        List<Collect> collectList = collectMapper.selectList(queryWrapper);
        return  collectList;
    }

}
